﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BCDto.Common.IP
{
    /// <summary>
    /// IP地址记录对象
    /// </summary>
    public class IPAddressRecordDto
    {
        /// <summary>
        /// IP地址记录Id
        /// </summary>
        public long IPAddressRecordId { get; set; }
        /// <summary>
        /// 开始地址段1
        /// </summary>
        public int StartIPOne { get; set; }
        /// <summary>
        /// 开始地址段2
        /// </summary>
        public int StartIPTwo { get; set; }

        /// <summary>
        /// 开始地址段3
        /// </summary>
        public int StartIPThree { get; set; }
        /// <summary>
        /// 开始地址段4
        /// </summary>
        public int StartIPFour { get; set; }
        /// <summary>
        /// 结束地址段1
        /// </summary>
        public int EndIPOne { get; set; }
        /// <summary>
        /// 结束地址段2
        /// </summary>
        public int EndIPTwo { get; set; }
        /// <summary>
        /// 结束地址段3
        /// </summary>
        public int EndIPThree { get; set; }
        /// <summary>
        /// 结束地址段4
        /// </summary>
        public int EndIPFour { get; set; }
        private string _startIP;
        /// <summary>
        /// 开始地址段
        /// </summary>
        public string StartIP
        {
            get { return _startIP; }
            set
            {
                _startIP = value;
                string[] ip = value.Split(".");
                if (value == "::1")
                {
                    ip = "127.0.0.1".Split(".");
                }

                StartIPOne = int.Parse(ip[0]);
                StartIPTwo = int.Parse(ip[1]);
                StartIPThree = int.Parse(ip[2]);
                StartIPFour = int.Parse(ip[3]);

            }
        }
        private string _endIP;
        /// <summary>
        /// 结束地址段
        /// </summary>
        public string EndIP
        {
            get { return _endIP; }
            set
            {
                _endIP = value;
                string[] ip = value.Split(".");
                if (value == "::1")
                {
                    ip = "127.0.0.1".Split(".");
                }
                EndIPOne = int.Parse(ip[0]);
                EndIPTwo = int.Parse(ip[1]);
                EndIPThree = int.Parse(ip[2]);
                EndIPFour = int.Parse(ip[3]);
            }
        }
        /// <summary>
        /// 网络分配组
        /// </summary>
        public string IANA { get; set; }
        /// <summary>
        /// 保留地址
        /// </summary>
        public string ReservedAddress { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }
    }
}
